package com.koicarp.university.graduate.web.controller.schoolInfoManage;

import com.koicarp.university.graduate.auth.annotation.OperLog;
import com.koicarp.university.graduate.auth.constant.ModuleNameEnum;
import com.koicarp.university.graduate.auth.constant.OperateLogTypeEnum;
import com.koicarp.university.graduate.service.entity.schoolInfoManage.Speciality;
import com.koicarp.university.graduate.service.service.schoolInfoManage.ISpecialityService;
import com.koicarp.university.graduate.service.vo.schoolInfoManage.SpecialityVo;
import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import com.koicarp.university.graudate.common.utils.UniversityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【学校基本信息：专业管理表】(Speciality)表控制层
 *
 * @author liutao
 * @since 2020-09-03 19:53:52
 */
@Slf4j
@RestController
@RequestMapping("speciality")
@RequiredArgsConstructor
@Api(tags = "(专业管理表)表控制层")
public class SpecialityController {
    /**
     * 服务对象
     */
    private final ISpecialityService specialityService;

    @PostMapping("getAllSpecialityInfo")
    @ApiOperation(value = "专业信息查询全部" ,notes = "专业信息查询全部")
    public UniversityResponse getAllSpecialityInfo(@RequestBody Speciality speciality){
        UniversityResponse response=null;
        try{
            System.out.println(speciality.getAcademyId());
            response = specialityService.getAllSpecialityInfo(speciality);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping("getSpecialityInfoWithPage")
    @ApiOperation(value = "专业信息查询-普通查询，分页" ,notes = "专业信息查询-普通查询，分页")
    public UniversityResponse getSpecialityInfoWithPage(SpecialityVo vo){
        UniversityResponse response=null;
        try{
            if (vo.getSort().equals("+id")){
                vo.setSort("asc");
            }else{
                vo.setSort("desc");
            }
            response = specialityService.getSpecialityInfoWithPage(vo);
        }catch (Exception e){
            log.error("查询失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("saveSpecialityInfo")
    @ApiOperation(value = "学院信息增加(单个)" ,notes = "学院信息增加(单个)")
    @OperLog(moduleName = ModuleNameEnum.SchoolSpe,type = OperateLogTypeEnum.CREATE,operDesc = "学院信息增加（单个）")
    public UniversityResponse saveSpecialityInfo(@RequestBody Speciality speciality){
        UniversityResponse response=null;
        try{
            response = specialityService.insert(speciality);
        }catch (Exception e){
            log.error("增加失败!",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("removeSpecialityInfo")
    @ApiOperation(value = "删除专业信息(单个)" ,notes = "删除专业信息（单个）")
    @OperLog(moduleName = ModuleNameEnum.SchoolSpe,type = OperateLogTypeEnum.DELETE,operDesc = "删除专业信息（单个）")
    public UniversityResponse removeSpecialityInfo(@RequestBody Speciality speciality){
        UniversityResponse response=null;
        try{
            response = specialityService.deleteById(speciality.getId());
        }catch (Exception e){
            log.error("删除失败！",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("removeListInfo")
    @ApiOperation(value = "删除专业信息(多个)" ,notes = "删除专业信息（多个）")
    @OperLog(moduleName = ModuleNameEnum.SchoolSpe,type = OperateLogTypeEnum.DELETE,operDesc = "删除专业信息（多个）")
    public UniversityResponse removeListInfo(@RequestBody List<Integer> idList){
        UniversityResponse response=null;
        try{
            response = specialityService.deleteListById(idList);
        }catch (Exception e){
            log.error("删除失败",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping("modifySpecialityInfo")
    @ApiOperation(value = "修改专业信息" ,notes = "修改专业信息")
    @OperLog(moduleName = ModuleNameEnum.SchoolSpe,type = OperateLogTypeEnum.UPDATE,operDesc = "修改专业信息")
    public UniversityResponse modifySpecialityInfo(@RequestBody Speciality speciality){
        UniversityResponse response=null;
        try{
            response = specialityService.update(speciality);
        }catch (Exception e){
            log.error("修改失败!",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

}